layui.define(['layer','jquery','form'], function (exports) {
    var $ = layui.jquery;
    var layer=layui.layer;
    var form = layui.form();

    //var index = parent.layer.getFrameIndex(window.name);

    form.on('checkbox(check)', function(data){
        if(data.elem.checked){
            $("input[name='checkbox']").prop("checked", true);
        }else{
            $("input[name='checkbox']").prop("checked", false);
        }  
        form.render('checkbox');      
    });

    /*显示维修详情*/
    $("button[data-opt=detail]").click(function(){
        var t_id=$(this).data('id');
        show_detail(t_id);
    });
    function show_detail(id){
        layer.open({
            type: 2,
            title: '报修详情',
            shadeClose: false,
            shade: 0.8,
            area: ['100%', '100%'],
            full:true,
            content: '?t=repair_detail&id='+id, //iframe的url
            end: function(){
                location.reload();
            }
        });
    }

    $("#btn_apply_repair").click(function(){
        add_dict();
    });
     
     function add_dict() {
        //iframe层
        layer.open({
            type: 2,
            title: '申请报修',
            shadeClose: false,
            shade: 0.8,
            area: ['100%', '100%'],
            full:true,
            content: '?t=repair_apple', //iframe的url
            end: function(){ 
                location.reload();
            }
        }); 
    }
    $("#btn_del").click(function(){
        var m_val="";
        $("[name='checkbox']:checked").each(function(i, obj) {
			m_val+=$(this).val()+",";
		});
        if(m_val.lastIndexOf(",")>0){
            m_val=m_val.substring(0,m_val.length-1) ;
        }
        if(m_val.length>0){ 
            layer.confirm('确定删除？',function(index){
                $.post("/srv/sdo.php", {tpl:"del_repair_typelist",id:m_val}, function (d, e) {
                    if(d=="ok"){
                        location.reload();
                    }
                });
            });
        }else{
            layer.msg('没有选择数据');
        } 
    });
    $('button[data-opt=update]').click(function(){
        var t_id=$(this).data('id');
        edit_grade(t_id);
    });
    function edit_grade(id) {
        //iframe层
        layer.open({
            type: 2,
            title: '申请报修',
            shadeClose: false,
            shade: 0.8,
            area: ['100%', '100%'],
            full:true,
            content: '?t=repair_apple&id='+id, //iframe的url
            end: function(){ 
                location.reload();
            }
        }); 
    }
    $('button[data-opt=del]').click(function(){
        var id=$(this).data('id');
        layer.confirm('确定删除？',function(index){
            $.post("./srv/sdo.php", {tpl:"del_mytakes",id:id}, function (d, e) {
                if(d=="ok"){
                    location.reload();
                }
            });
        });
    });
    $("#btn_ref").click(function(){
        location.reload();
    });
    $("#btn_search").bind("click",function(){
        var service_sn    = $("#service_sn").val();
        var repair_status = $("#repair_status option:selected").val();
        location.href="?t=repair_mytakes&service_sn="+service_sn+"&repair_status="+repair_status;
    });

    $("#btn_callback").click(function(){
        var m_val=$(this).attr('data-id');
        layer.confirm('确定撤回此申请吗？',function(index){
            $.post("/srv/sdo.php", {tpl:"repair_callback",id:m_val}, function (d, e) {
                if(d=="ok"){
                    location.reload();
                }
            });
        });

    });

    
    exports('repair_mytakes', {});
});